#!/bin/bash
source ./var
source ./Tmpdir
source ./Install_jdk8
tomcat(){
    java -version &> /dev/null
    if [ $? != 0 ];then
        echoYellow "系统中可能没有安装jdk8，现在即将安装，然后在安装tomcat8"
        #调用Install_jdk8函数
        Install_jdk8
        echoGreen "jdk8已安装成功……，下面即将安装tomcat8"
        
        tomcat_version="apache-tomcat-8.5.53.tar.gz"
        TAR_tomccat="apache-tomcat-8.5.53"
        #调用Tmpdir
        Tmpdir
        cd $dir && wget -V &> /dev/null || yum -y install wget
        pwd
        pwd
        pwd
        [ -d /usr/local/tomcat ] && echoRed "检测到/usr/local下已安装tomcat，故而退出" && rm -rf $dir && exit 1
        wget $ip/${tomcat_version} && tar xf ${tomcat_version} -C /usr/local && ln -sv /usr/local/${TAR_tomccat}/ /usr/local/tomcat
        /usr/local/tomcat/bin/version.sh &> /dev/null  && echoGreen "已完成安装，可尽情享用" || echoYellow "可能安装有问题，请检查是否>有java环境"
        rm -rf $dir
                   
    else
        echoGreen "系统中发现已安装jdk，路径如下：`which java`"
        echoGreen "系统中发现已安装jdk，版本如下："
        echoGreen "$(java -version)"
        echoGreen "即将安装tomcat"
    fi
        pwd
        pwd
        pwd
        
        tomcat_version="apache-tomcat-8.5.53.tar.gz"
        TAR_tomccat="apache-tomcat-8.5.53"

        #调用Tmpdir
        Tmpdir
        cd $dir && wget -V &> /dev/null || yum -y install wget
        pwd
        pwd
        pwd
        [ -d /usr/local/tomcat ] && echoRed "检测到/usr/local下已安装tomcat，故而退出" && rm -rf $dir && exit 1
        wget $ip/${tomcat_version} && tar xf ${tomcat_version} -C /usr/local && ln -sv /usr/local/${TAR_tomccat}/ /usr/local/tomcat
        /usr/local/tomcat/bin/version.sh &> /dev/null  && echoGreen "已完成安装，可尽情享用" || echoYellow "可能安装有问题，请检查是否有java环境"
        rm -rf $dir
}
